package com.sw.fastdev.activity;

import android.support.design.widget.NavigationView;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import com.githang.viewpagerindicator.IconTabPageIndicator;
import com.jaeger.library.StatusBarUtil;
import com.sw.fastdev.R;
import com.sw.fastdev.adapter.FragmentAdapter;
import com.sw.fastdev.fragment.BaseFragment;
import com.sw.fastdev.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private Toolbar toolbar;
    private NavigationView nv_menu;
    private DrawerLayout drawerLayout;
    private ViewPager viewPager;
    private IconTabPageIndicator indicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LogUtils.w("main","主页测试");
        setSupportActionBar(toolbar);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
        if(toggle != null){
            drawerLayout.setDrawerListener(toggle);
            toggle.syncState();
            mAlpha = 0;
            StatusBarUtil.setTranslucentForDrawerLayout(MainActivity.this,drawerLayout,mAlpha);
        }
    }

    @Override
    protected void initView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        nv_menu = (NavigationView) findViewById(R.id.nv_menu);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        viewPager = (ViewPager) findViewById(R.id.view_pager);
        indicator = (IconTabPageIndicator) findViewById(R.id.indicator);

        List<BaseFragment> fragments = initFragments();
        FragmentAdapter adapter = new FragmentAdapter(fragments, getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        indicator.setViewPager(viewPager);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setStatusBar() {
        mStatusBarColor = getResources().getColor(R.color.colorPrimary);
        mAlpha = 0;
        StatusBarUtil.setColorForDrawerLayout(MainActivity.this, (DrawerLayout) findViewById(R.id.drawer_layout),mStatusBarColor,mAlpha);
    }

    private List<BaseFragment> initFragments() {
        List<BaseFragment> fragments = new ArrayList<BaseFragment>();

        BaseFragment userFragment = new BaseFragment();
        userFragment.setTitle("用户");
        userFragment.setIconId(R.drawable.tab_user_selector);
        fragments.add(userFragment);

        BaseFragment noteFragment = new BaseFragment();
        noteFragment.setTitle("记事本");
        noteFragment.setIconId(R.drawable.tab_record_selector);
        fragments.add(noteFragment);

        BaseFragment contactFragment = new BaseFragment();
        contactFragment.setTitle("联系人");
        contactFragment.setIconId(R.drawable.tab_user_selector);
        fragments.add(contactFragment);

        BaseFragment recordFragment = new BaseFragment();
        recordFragment.setTitle("记录");
        recordFragment.setIconId(R.drawable.tab_record_selector);
        fragments.add(recordFragment);

        BaseFragment mFragment = new BaseFragment();
        mFragment.setTitle("我的");
        mFragment.setIconId(R.drawable.tab_user_selector);
        fragments.add(mFragment);

        return fragments;
    }
}
